<template>
  <div class="login-container">
    <div class="login-form">
      <h2 class="login-title">登录</h2>
      <!-- <form> -->
      <div class="form-group">
        <label for="username">用户名</label>
        <input type="text" id="username" v-model="username" />
      </div>
      <div class="form-group">
        <label for="password">密码</label>
        <input type="password" id="password" v-model="password" />
      </div>
      <button class="login-button" @click="login">登录</button>
      <!-- </form> -->
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
let username = ref("");
let password = ref("");
const router = useRouter();
const login = () => {
  if (username.value && password.value) {
    // 用户名和密码均不为空，执行跳转
    const screenUser = {
      username: username.value,
      password: password.value,
    };
    localStorage.setItem("ScreenUser", JSON.stringify(screenUser));
    router.push("/home");
  } else {
    // 用户名或密码为空，给出提示或执行其他操作
    alert("用户名和密码不能为空");
  }
};
</script>

<style>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.login-form {
  max-width: 400px;
  padding: 20px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: #fff;
}

.login-title {
  text-align: center;
  margin-bottom: 20px;
  color: #333;
}

.form-group {
  margin-bottom: 15px;
}

label {
  display: block;
  margin-bottom: 5px;
  color: #333;
}

input {
  width: 250px;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.login-button {
  width: 100%;
  padding: 10px;
  color: #fff;
  background-color: #007bff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.login-button:hover {
  background-color: #0069d9;
}
</style>
